package com.pengtu.entity.asset.equipment;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Department;
import com.pengtu.utils.reflection.ConvertUtils;

@Entity
@Table(name = "T_ASST_EQUIP_INFO")
public class EquipInformation extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String equipmentModel; // 设备名称及型号
	private String equipmentNo; // 设备编号
	private String dataAcquisitionWorkstation; // 数据采集工作站
	private Department department; // 所属部门
	private String stored; // 设备存放地
	private Set<EquipItem> items = new HashSet<EquipItem>(); // // 设备适用项目
	private Double price;
	private String brand;
	
	private String sindex;
	private String count;
	private String unit;
	private String factory;
	private Date manufacturer;
	private String productNo;
	private String unitizeNo;
	private String officer;
	private String asstState;
	private Date buyDate;
	
	
	

	@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinColumn(name = "DEPTNAME")
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	@Column(name = "STORED")
	public String getStored() {
		return stored;
	}

	public void setStored(String stored) {
		this.stored = stored;
	}

	@Column(name = "EUQIPMENTMODEL")
	public String getEquipmentModel() {
		return equipmentModel;
	}

	public void setEquipmentModel(String equipmentModel) {
		this.equipmentModel = equipmentModel;
	}

	@Column(name = "EQUIPMENTNO", unique = true)
	public String getEquipmentNo() {
		return equipmentNo;
	}

	public void setEquipmentNo(String equipmentNo) {
		this.equipmentNo = equipmentNo;
	}

	@Column(name = "DATAACQUISITIONWOEKSTATION")
	public String getDataAcquisitionWorkstation() {
		return dataAcquisitionWorkstation;
	}

	public void setDataAcquisitionWorkstation(String dataAcquisitionWorkstation) {
		this.dataAcquisitionWorkstation = dataAcquisitionWorkstation;
	}

	public void addItem(EquipItem item) {
		this.items.add(item);
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinColumn(name = "ITEMID")
	@Fetch(FetchMode.SELECT)
	public Set<EquipItem> getItems() {
		return items;
	}

	public void setItems(Set<EquipItem> items) {
		this.items = items;
	}

	@Column(name="PRICE")
	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}
	
	@Column(name="BRAND")
	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}
	
	@Column(name="SINDEX")
	public String getSindex() {
		return sindex;
	}

	public void setSindex(String sindex) {
		this.sindex = sindex;
	}
	
	@Column(name="COUNT")
	public String getCount() {
		return count;
	}

	public void setCount(String count) {
		this.count = count;
	}
	
	@Column(name="UNIT")
	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}
	
	@Column(name="FACTORY")
	public String getFactory() {
		return factory;
	}

	public void setFactory(String factory) {
		this.factory = factory;
	}

	@Column(name="MANUFACTURER")
	public Date getManufacturer() {
		return manufacturer;
	}

	public void setManufacturer(Date manufacturer) {
		this.manufacturer = manufacturer;
	}
	
	@Column(name="PRODUCTNO")
	public String getProductNo() {
		return productNo;
	}

	public void setProductNo(String productNo) {
		this.productNo = productNo;
	}
	
	@Column(name="UNITIZENO")
	public String getUnitizeNo() {
		return unitizeNo;
	}

	public void setUnitizeNo(String unitizeNo) {
		this.unitizeNo = unitizeNo;
	}
	
	@Column(name="OFFICER")
	public String getOfficer() {
		return officer;
	}

	public void setOfficer(String officer) {
		this.officer = officer;
	}
	
	@Column(name="ASSTSTATE")
	public String getAsstState() {
		return asstState;
	}

	public void setAsstState(String asstState) {
		this.asstState = asstState;
	}
	
	
	@Column(name="BUYDATE")
	public Date getBuyDate() {
		return buyDate;
	}

	public void setBuyDate(Date buyDate) {
		this.buyDate = buyDate;
	}

	// 非持久化属性.
	@Transient
	@SuppressWarnings("unchecked")
	public List<String> getItemCodes() {
		return ConvertUtils.convertElementPropertyToList(items, "itemCode");
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public EquipInformation() {
		super();
	}

}
